<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>gozerlib.plugs.core &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../../index.html" />
    <link rel="up" title="gozerlib.plugs" href="index.html" />
    <link rel="next" title="gozerlib.plugs.count" href="count.html" />
    <link rel="prev" title="gozerlib.plugs.choice" href="choice.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="count.html" title="gozerlib.plugs.count"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="choice.html" title="gozerlib.plugs.choice"
             accesskey="P">previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">gozerlib.plugs</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-gozerlib.plugs.core">
<h1>gozerlib.plugs.core<a class="headerlink" href="#module-gozerlib.plugs.core" title="Permalink to this headline">¶</a></h1>
<p>core bot commands.</p>
<dl class="function">
<dt id="gozerlib.plugs.core.handle_apro">
<tt class="descclassname">gozerlib.plugs.core.</tt><tt class="descname">handle_apro</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.core.handle_apro" title="Permalink to this definition">¶</a></dt>
<dd>apro &lt;cmnd&gt; .. apropos for command.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.core.handle_commands">
<tt class="descclassname">gozerlib.plugs.core.</tt><tt class="descname">handle_commands</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.core.handle_commands" title="Permalink to this definition">¶</a></dt>
<dd>commands &lt;plugin&gt; .. show commands of &lt;plugin&gt;.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.core.handle_encoding">
<tt class="descclassname">gozerlib.plugs.core.</tt><tt class="descname">handle_encoding</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.core.handle_encoding" title="Permalink to this definition">¶</a></dt>
<dd>show default encoding.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.core.handle_help">
<tt class="descclassname">gozerlib.plugs.core.</tt><tt class="descname">handle_help</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.core.handle_help" title="Permalink to this definition">¶</a></dt>
<dd>help [&lt;cmnd&gt;|&lt;plugin&gt;] .. show help on plugin/command or show basic help msg.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.core.handle_list">
<tt class="descclassname">gozerlib.plugs.core.</tt><tt class="descname">handle_list</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.core.handle_list" title="Permalink to this definition">¶</a></dt>
<dd>list [&lt;plugin&gt;] .. list loaded plugins or list commands provided by         plugin.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.core.handle_perm">
<tt class="descclassname">gozerlib.plugs.core.</tt><tt class="descname">handle_perm</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.core.handle_perm" title="Permalink to this definition">¶</a></dt>
<dd>perm &lt;command&gt; .. get permission of command.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.core.handle_uptime">
<tt class="descclassname">gozerlib.plugs.core.</tt><tt class="descname">handle_uptime</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.core.handle_uptime" title="Permalink to this definition">¶</a></dt>
<dd>show uptime.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.core.handle_version">
<tt class="descclassname">gozerlib.plugs.core.</tt><tt class="descname">handle_version</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.core.handle_version" title="Permalink to this definition">¶</a></dt>
<dd>show bot&#8217;s version.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.core.handle_versions">
<tt class="descclassname">gozerlib.plugs.core.</tt><tt class="descname">handle_versions</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.core.handle_versions" title="Permalink to this definition">¶</a></dt>
<dd>show versions of all loaded modules (if available).</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.core.handle_whatcommands">
<tt class="descclassname">gozerlib.plugs.core.</tt><tt class="descname">handle_whatcommands</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.core.handle_whatcommands" title="Permalink to this definition">¶</a></dt>
<dd>show all commands with permission.</dd></dl>

<dl class="function">
<dt id="gozerlib.plugs.core.handle_whereis">
<tt class="descclassname">gozerlib.plugs.core.</tt><tt class="descname">handle_whereis</tt><big>(</big><em>bot</em>, <em>ievent</em><big>)</big><a class="headerlink" href="#gozerlib.plugs.core.handle_whereis" title="Permalink to this definition">¶</a></dt>
<dd>whereis &lt;cmnd&gt; .. locate a command.</dd></dl>

<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361</pre></td><td class="code"><div class="highlight"><pre><span class="c"># plugs/core.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; core bot commands. &quot;&quot;&quot;</span>


<span class="c"># gozerbot imports</span>
<span class="kn">from</span> <span class="nn">gozerlib.utils.timeutils</span> <span class="kn">import</span> <span class="n">elapsedstring</span>
<span class="kn">from</span> <span class="nn">gozerlib.utils.generic</span> <span class="kn">import</span> <span class="n">getversion</span>
<span class="kn">from</span> <span class="nn">gozerlib.utils.exception</span> <span class="kn">import</span> <span class="n">handle_exception</span>
<span class="kn">from</span> <span class="nn">gozerlib.commands</span> <span class="kn">import</span> <span class="n">cmnds</span>
<span class="kn">from</span> <span class="nn">gozerlib.examples</span> <span class="kn">import</span> <span class="n">examples</span>
<span class="kn">from</span> <span class="nn">gozerlib.plugins</span> <span class="kn">import</span> <span class="n">plugs</span>
<span class="kn">from</span> <span class="nn">gozerlib.aliases</span> <span class="kn">import</span> <span class="n">aliasreverse</span><span class="p">,</span> <span class="n">aliasset</span><span class="p">,</span> <span class="n">getaliases</span>
<span class="kn">from</span> <span class="nn">gozerlib.users</span> <span class="kn">import</span> <span class="n">GozerUsers</span>
<span class="kn">from</span> <span class="nn">gozerlib.admin</span> <span class="kn">import</span> <span class="n">plugin_packages</span>
<span class="kn">from</span> <span class="nn">gozerlib.persist.persist</span> <span class="kn">import</span> <span class="n">Persist</span>

<span class="c"># basic imports</span>
<span class="kn">from</span> <span class="nn">sets</span> <span class="kn">import</span> <span class="n">Set</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">threading</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">copy</span>

<span class="k">def</span> <span class="nf">handle_encoding</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; show default encoding. &quot;&quot;&quot;</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;default encoding is </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">sys</span><span class="o">.</span><span class="n">getdefaultencoding</span><span class="p">())</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;encoding&#39;</span><span class="p">,</span> <span class="n">handle_encoding</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;encoding&#39;</span><span class="p">,</span> <span class="s">&#39;show default encoding&#39;</span><span class="p">,</span> <span class="s">&#39;encoding&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;encoding&#39;)</span>

<span class="k">def</span> <span class="nf">handle_uptime</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; show uptime. &quot;&quot;&quot;</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;uptime is </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">elapsedstring</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span><span class="o">-</span><span class="n">bot</span><span class="o">.</span><span class="n">starttime</span><span class="p">))</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;uptime&#39;</span><span class="p">,</span> <span class="n">handle_uptime</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">,</span> <span class="s">&#39;JCOLL&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;uptime&#39;</span><span class="p">,</span> <span class="s">&#39;show uptime of the bot&#39;</span><span class="p">,</span> <span class="s">&#39;uptime&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;up&#39;</span><span class="p">,</span> <span class="s">&#39;uptime&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;uptime&#39;, &#39;uptime is&#39;)</span>

<span class="k">def</span> <span class="nf">handle_list</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; list [&lt;plugin&gt;] .. list loaded plugins or list commands provided by \</span>
<span class="sd">        plugin.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span><span class="p">:</span>
        <span class="c"># no arguments given .. show plugins</span>
        <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">pluglist</span> <span class="o">=</span> <span class="n">plugs</span><span class="o">.</span><span class="n">list</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">plug</span> <span class="ow">in</span> <span class="n">pluglist</span><span class="p">:</span>

            <span class="k">if</span> <span class="s">&#39;__init__&#39;</span> <span class="ow">in</span> <span class="n">plug</span><span class="p">:</span>
                <span class="k">continue</span>

            <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">plug</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;.&#39;</span><span class="p">)[</span><span class="o">-</span><span class="mf">1</span><span class="p">])</span>

        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;loaded plugins: &#39;</span><span class="p">,</span> <span class="n">result</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="c"># show commands of &lt;what&gt; plugin</span>
    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">cmnds</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
        <span class="k">if</span> <span class="n">what</span> <span class="o">==</span> <span class="n">j</span><span class="o">.</span><span class="n">plugname</span><span class="p">:</span>
            <span class="n">txt</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
            <span class="n">alias</span> <span class="o">=</span> <span class="n">aliasreverse</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">alias</span><span class="p">:</span>
                <span class="n">txt</span> <span class="o">+=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">alias</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">txt</span> <span class="o">=</span> <span class="n">i</span>
            <span class="k">if</span> <span class="n">txt</span><span class="p">:</span>
                <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">txt</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">result</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> has the following commands: &#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">,</span> <span class="n">result</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no commands found for plugin </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;list&#39;</span><span class="p">,</span> <span class="n">handle_list</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">,</span> <span class="s">&#39;CLOUD&#39;</span><span class="p">],</span> <span class="n">threaded</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;list&#39;</span><span class="p">,</span> <span class="s">&#39;list registered plugins or list commands in plugin&#39;</span><span class="p">,</span> <span class="s">&#39;1) list 2) list rss&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;list&#39;, &#39;core&#39;)</span>

<span class="k">def</span> <span class="nf">handle_commands</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; commands &lt;plugin&gt; .. show commands of &lt;plugin&gt;. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">plugin</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;plugin&gt; .. see the list command for available </span><span class="se">\</span>
<span class="s">plugins&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">plugs</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">plugin</span><span class="p">):</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no </span><span class="si">%s</span><span class="s"> plugin is loaded .. see the available command for </span><span class="se">\</span>
<span class="s">available plugins (reload to enable)&#39;</span> <span class="o">%</span> <span class="n">plugin</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="n">cp</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">cmnds</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">cp</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
        <span class="k">if</span> <span class="n">plugin</span> <span class="o">==</span> <span class="n">j</span><span class="o">.</span><span class="n">plugname</span><span class="p">:</span>
            <span class="n">txt</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
            <span class="n">alias</span> <span class="o">=</span> <span class="n">aliasreverse</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">alias</span><span class="p">:</span>
                <span class="n">txt</span> <span class="o">+=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">alias</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">txt</span> <span class="o">=</span> <span class="n">i</span>
            <span class="k">if</span> <span class="n">txt</span><span class="p">:</span>
                <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">txt</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">result</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> has the following commands: &#39;</span> <span class="o">%</span> <span class="n">plugin</span><span class="p">,</span> <span class="n">result</span><span class="p">,</span> \
<span class="n">dot</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no commands found for plugin </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">plugin</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;commands&#39;</span><span class="p">,</span> <span class="n">handle_commands</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">,</span> <span class="s">&#39;CLOUD&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;commands&#39;</span><span class="p">,</span> <span class="s">&#39;show commands of &lt;plugin&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;1) commands core&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;commands core&#39;, &#39;uptime&#39;)</span>

<span class="k">def</span> <span class="nf">handle_perm</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; perm &lt;command&gt; .. get permission of command. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">cmnd</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&quot;&lt;cmnd&gt;&quot;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">aliases</span> <span class="o">=</span> <span class="n">getaliases</span><span class="p">()</span>
        <span class="n">cmnd</span> <span class="o">=</span> <span class="n">aliases</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">cmnd</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
        <span class="k">pass</span>

    <span class="n">perms</span> <span class="o">=</span> <span class="n">cmnds</span><span class="o">.</span><span class="n">perms</span><span class="p">(</span><span class="n">cmnd</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">perms</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> command needs </span><span class="si">%s</span><span class="s"> permission&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">cmnd</span><span class="p">,</span> <span class="n">perms</span><span class="p">))</span>
        <span class="k">return</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find perm for </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="n">cmnd</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;perm&#39;</span><span class="p">,</span> <span class="n">handle_perm</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;perm&#39;</span><span class="p">,</span> <span class="s">&#39;show permission of command&#39;</span><span class="p">,</span> <span class="s">&#39;perm quit&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;perm version&#39;, &#39;USER&#39;)</span>

<span class="k">def</span> <span class="nf">handle_version</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; show bot&#39;s version. &quot;&quot;&quot;</span>

    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="n">getversion</span><span class="p">(</span><span class="n">bot</span><span class="o">.</span><span class="n">type</span><span class="o">.</span><span class="n">upper</span><span class="p">()))</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;version&#39;</span><span class="p">,</span> <span class="n">handle_version</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">,</span> <span class="s">&#39;JCOLL&#39;</span><span class="p">,</span> <span class="s">&#39;CLOUD&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;version&#39;</span><span class="p">,</span> <span class="s">&#39;show version of the bot&#39;</span><span class="p">,</span> <span class="s">&#39;version&#39;</span><span class="p">)</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;v&#39;</span><span class="p">,</span> <span class="s">&#39;version&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;version&#39;, &#39;GOZERBOT&#39;)</span>

<span class="k">def</span> <span class="nf">handle_whereis</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; whereis &lt;cmnd&gt; .. locate a command. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">cmnd</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;cmnd&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">plugin</span> <span class="o">=</span> <span class="n">cmnds</span><span class="o">.</span><span class="n">whereis</span><span class="p">(</span><span class="n">cmnd</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">plugin</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s"> command is in: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span>  <span class="p">(</span><span class="n">cmnd</span><span class="p">,</span> <span class="n">plugin</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;can&#39;t find &quot;</span> <span class="o">+</span> <span class="n">cmnd</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;whereis&#39;</span><span class="p">,</span> <span class="n">handle_whereis</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;whereis&#39;</span><span class="p">,</span> <span class="s">&#39;whereis &lt;cmnd&gt; .. show in which plugins &lt;what&gt; is&#39;</span><span class="p">,</span> <span class="s">&#39;whereis test&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;whereis version&#39;, &#39;core&#39;)</span>

<span class="k">def</span> <span class="nf">handle_help</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; help [&lt;cmnd&gt;|&lt;plugin&gt;] .. show help on plugin/command or show basic help msg. &quot;&quot;&quot;</span>


    <span class="k">try</span><span class="p">:</span>
        <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">pluginslist</span> <span class="o">=</span> <span class="n">Persist</span><span class="p">(</span><span class="s">&#39;pluginlist&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">data</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;available plugins: &quot;</span><span class="p">,</span> <span class="n">pluginslist</span><span class="p">)</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;help &lt;plugin&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">cmndhelp</span> <span class="o">=</span> <span class="n">cmnds</span><span class="o">.</span><span class="n">gethelp</span><span class="p">(</span><span class="n">what</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">cmndhelp</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="n">cmndhelp</span><span class="p">)</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;examples: &quot;</span> <span class="o">+</span> <span class="n">examples</span><span class="p">[</span><span class="n">what</span><span class="p">]</span><span class="o">.</span><span class="n">example</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="k">pass</span>

        <span class="k">return</span>

    <span class="n">plugin</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="n">modname</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>

    <span class="k">for</span> <span class="n">package</span> <span class="ow">in</span> <span class="n">plugin_packages</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>
             <span class="n">modname</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">package</span><span class="p">,</span> <span class="n">what</span><span class="p">)</span>
             <span class="n">plugs</span><span class="o">.</span><span class="n">needreloadcheck</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">,</span> <span class="n">modname</span><span class="p">)</span>
             <span class="n">plugin</span> <span class="o">=</span> <span class="n">plugs</span><span class="o">.</span><span class="n">store</span><span class="p">[</span><span class="n">modname</span><span class="p">]</span>
        <span class="k">except</span><span class="p">(</span> <span class="ne">KeyError</span><span class="p">,</span> <span class="ne">ImportError</span><span class="p">):</span>
             <span class="k">pass</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">plugin</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;no </span><span class="si">%s</span><span class="s"> plugin loaded&quot;</span> <span class="o">%</span> <span class="n">what</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="k">try</span><span class="p">:</span>
          <span class="n">phelp</span> <span class="o">=</span> <span class="n">plugin</span><span class="o">.</span><span class="n">__doc__</span>
    <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no description of </span><span class="si">%s</span><span class="s"> plugin available&#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">)</span>
    
    <span class="n">cmndresult</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="k">if</span> <span class="n">phelp</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;plugin description: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">phelp</span><span class="p">)</span>

    <span class="n">users</span> <span class="o">=</span> <span class="n">GozerUsers</span><span class="p">()</span>
    <span class="n">perms</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">users</span><span class="o">.</span><span class="n">getperms</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">))</span>

    <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">cmnds</span><span class="o">.</span><span class="n">store</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
        <span class="k">if</span> <span class="n">what</span> <span class="o">==</span> <span class="n">j</span><span class="o">.</span><span class="n">plugname</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">i</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">cmndresult</span><span class="p">:</span>
                <span class="n">cmndresult</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">cmndresult</span><span class="p">:</span>
        <span class="n">cmndresult</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
        <span class="n">resultstr</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">cmndresult</span><span class="p">:</span>
            <span class="n">alias</span> <span class="o">=</span> <span class="n">aliasreverse</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">alias</span><span class="p">:</span>
                <span class="n">resultstr</span> <span class="o">+=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">) .. &quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">alias</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">resultstr</span> <span class="o">+=</span> <span class="s">&quot;</span><span class="si">%s</span><span class="s"> .. &quot;</span> <span class="o">%</span> <span class="n">i</span>

        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;commands: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">resultstr</span><span class="p">[:</span><span class="o">-</span><span class="mf">4</span><span class="p">])</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;see help &lt;command&gt;&#39;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no commands available&#39;</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;help&#39;</span><span class="p">,</span> <span class="n">handle_help</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">])</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;help&#39;</span><span class="p">,</span> <span class="s">&#39;get help on &lt;cmnd&gt; or &lt;plugin&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;1) help test 2) help misc&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;help core&#39;, &#39;version&#39;)</span>

<span class="k">def</span> <span class="nf">handle_apro</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; apro &lt;cmnd&gt; .. apropos for command. &quot;&quot;&quot;</span>

    <span class="k">try</span><span class="p">:</span>
        <span class="n">what</span> <span class="o">=</span> <span class="n">ievent</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mf">0</span><span class="p">]</span>
    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;what&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="n">users</span> <span class="o">=</span> <span class="n">GozerUsers</span><span class="p">()</span>
    <span class="n">perms</span> <span class="o">=</span> <span class="n">users</span><span class="o">.</span><span class="n">getperms</span><span class="p">(</span><span class="n">ievent</span><span class="o">.</span><span class="n">userhost</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">cmnds</span><span class="o">.</span><span class="n">apropos</span><span class="p">(</span><span class="n">re</span><span class="o">.</span><span class="n">escape</span><span class="p">(</span><span class="n">what</span><span class="p">)):</span>
        <span class="n">alias</span> <span class="o">=</span> <span class="n">aliasreverse</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">alias</span><span class="p">:</span>
            <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> (</span><span class="si">%s</span><span class="s">)&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">alias</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">i</span><span class="p">)</span>

    <span class="n">res</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="n">aliases</span> <span class="o">=</span> <span class="n">getaliases</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">alias</span> <span class="ow">in</span> <span class="n">aliases</span><span class="o">.</span><span class="n">data</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">what</span> <span class="ow">in</span> <span class="n">alias</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">what</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
            <span class="n">res</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">alias</span><span class="p">)</span>

    <span class="n">result</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;commands matching </span><span class="si">%s</span><span class="s">: &quot;</span> <span class="o">%</span> <span class="n">what</span><span class="p">,</span> <span class="n">result</span> <span class="p">,</span> <span class="n">nr</span><span class="o">=</span><span class="mf">1</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span> 
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no matching commands found for </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">what</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;apro&#39;</span><span class="p">,</span> <span class="n">handle_apro</span><span class="p">,</span> <span class="p">[</span><span class="s">&#39;USER&#39;</span><span class="p">,</span> <span class="s">&#39;WEB&#39;</span><span class="p">])</span>
<span class="n">aliasset</span><span class="p">(</span><span class="s">&#39;apropos&#39;</span><span class="p">,</span> <span class="s">&#39;apro&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;apro&#39;</span><span class="p">,</span> <span class="s">&#39;apro &lt;what&gt; .. search for commands that contain &lt;what&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;apro com&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;apro ver&#39;, &#39;version&#39;)</span>

<span class="k">def</span> <span class="nf">handle_whatcommands</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; show all commands with permission. &quot;&quot;&quot;</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">missing</span><span class="p">(</span><span class="s">&#39;&lt;perm&gt;&#39;</span><span class="p">)</span>
        <span class="k">return</span>

    <span class="n">result</span> <span class="o">=</span> <span class="n">cmnds</span><span class="o">.</span><span class="n">store</span>
    <span class="n">res</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">cmnd</span> <span class="ow">in</span> <span class="n">result</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
        <span class="k">if</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span> <span class="ow">in</span> <span class="n">cmnd</span><span class="o">.</span><span class="n">perms</span><span class="p">:</span>
            <span class="n">res</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cmnd</span><span class="o">.</span><span class="n">cmnd</span><span class="p">)</span>

    <span class="n">res</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>

    <span class="k">if</span> <span class="ow">not</span> <span class="n">result</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;no commands known for permission </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&#39;commands known for permission </span><span class="si">%s</span><span class="s">: &#39;</span> <span class="o">%</span> <span class="n">ievent</span><span class="o">.</span><span class="n">rest</span><span class="p">,</span> <span class="n">res</span><span class="p">)</span>

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;whatcommands&#39;</span><span class="p">,</span> <span class="n">handle_whatcommands</span><span class="p">,</span> <span class="s">&#39;USER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;whatcommands&#39;</span><span class="p">,</span> <span class="s">&#39;show commands with permission &lt;perm&gt;&#39;</span><span class="p">,</span> <span class="s">&#39;whatcommands USER&#39;</span><span class="p">)</span>
<span class="c">#tests.add(&#39;whatcommands USER&#39;, &#39;version&#39;)</span>

<span class="k">def</span> <span class="nf">handle_versions</span><span class="p">(</span><span class="n">bot</span><span class="p">,</span> <span class="n">ievent</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot; show versions of all loaded modules (if available). &quot;&quot;&quot;</span>

    <span class="n">versions</span> <span class="o">=</span> <span class="p">{}</span>
    <span class="k">for</span> <span class="n">mod</span> <span class="ow">in</span> <span class="n">copy</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">modules</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">versions</span><span class="p">[</span><span class="n">mod</span><span class="p">]</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">modules</span><span class="p">[</span><span class="n">mod</span><span class="p">]</span><span class="o">.</span><span class="n">__version__</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">versions</span><span class="p">[</span><span class="s">&#39;python&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">version</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">,</span> <span class="n">ex</span><span class="p">:</span>
            <span class="k">pass</span>
    <span class="n">ievent</span><span class="o">.</span><span class="n">reply</span><span class="p">(</span><span class="s">&quot;versions ==&gt; &quot;</span><span class="p">,</span> <span class="n">versions</span><span class="p">)</span>
    

<span class="n">cmnds</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;versions&#39;</span><span class="p">,</span> <span class="n">handle_versions</span><span class="p">,</span> <span class="s">&#39;OPER&#39;</span><span class="p">)</span>
<span class="n">examples</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&#39;versions&#39;</span><span class="p">,</span> <span class="s">&#39;show versions of all loaded modules&#39;</span><span class="p">,</span> <span class="s">&#39;versions&#39;</span><span class="p">)</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">gozerlib.plugs.core</a><ul>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="choice.html"
                                  title="previous chapter">gozerlib.plugs.choice</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="count.html"
                                  title="next chapter">gozerlib.plugs.count</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../../_sources/gozerlib/plugs/core.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="count.html" title="gozerlib.plugs.count"
             >next</a> |</li>
        <li class="right" >
          <a href="choice.html" title="gozerlib.plugs.choice"
             >previous</a> |</li>
        <li><a href="../../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li>
          <li><a href="index.html" >gozerlib.plugs</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>